package com.uphone.magicleafteacher.pro.activity;

import android.view.View;

import com.radish.baselibrary.Intent.IntentData;
import com.uphone.magicleafteacher.MyApp;
import com.uphone.magicleafteacher.R;
import com.uphone.magicleafteacher.base.BaseListActivity;
import com.uphone.magicleafteacher.http.ApiService;
import com.uphone.magicleafteacher.pro.adapter.CourseLiveWorkAdapter;
import com.uphone.magicleafteacher.util.CommonUtil;
import com.uphone.magicleafteacher.util.GsonUtils;
import com.uphone.magicleafteacher.vo.ClassWorkBean;

import java.util.List;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

public class CourseLiveWorkActivity extends BaseListActivity<ClassWorkBean.HomeworkBean, CourseLiveWorkAdapter> {

    @IntentData
    private int id;

    @Override
    protected Observable<ResponseBody> loadData(ApiService apiService) {
        return MyApp.apiService(ApiService.class)
                .liveClassWork(id + "", "" + page, "10");
    }

    @Override
    protected List<ClassWorkBean.HomeworkBean> getDataList(String json) {
        ClassWorkBean bean = GsonUtils.getGson().fromJson(json, ClassWorkBean.class);
        if (bean != null)
            return bean.getHomework();
        return null;
    }

    @Override
    protected void itemClick(CourseLiveWorkAdapter adapter, View view, int position) {

    }

    @Override
    protected CourseLiveWorkAdapter initAdapter() {
        return new CourseLiveWorkAdapter();
    }

    @Override
    protected void initBundle() {

    }

    @Override
    protected void initTitle() {
        initTitle("查看作业");
    }

    @Override
    protected void itemChildClick(CourseLiveWorkAdapter adapter, View view, int position) {
        super.itemChildClick(adapter, view, position);
        switch (view.getId()) {
            case R.id.iv_pic:
                CommonUtil.openBigPic(CommonUtil.getImageUrl(mAdapter.getItem(position).getWorkPic()));
                break;
        }
    }
}
